<template>
    <div class="enterpriseDetails">
       <el-card>
            <span class="_before">基本信息</span>
            <el-row class="marginTop10 topContent">
                <el-col :span="24" class="marginTop10">公司名称: {{companyInfoData.name || '--'}}</el-col>
                <el-col :span="24" class="marginTop10">统一社会信用代码: {{companyInfoData.invoiceTaxnum || '--'}}</el-col>
                <el-col :span="24" class="marginTop10">企业角色: {{chekMainBusiness(companyInfoData.mainBusiness)}}</el-col>
                <el-col :span="24" class="marginTop10">认证完成时间: {{formatDate(companyInfoData.examineTime,4) || '--'}}</el-col>
                <el-col :span="24" class="marginTop10">
                    <el-row>
                        <el-col :span="24">企业LOGO:</el-col>
                        <el-col :span="2">
                            <template v-if="companyInfoData.companyLogo">
                                <el-image style="width: 100%" :src="JSON.parse(companyInfoData.companyLogo)[0].url" fit="fill" />
                            </template>
                            <template v-else>暂无图片</template>
                        </el-col>
                    </el-row>
                </el-col>
                <el-col :span="24" class="marginTop10">
                    <el-row>
                        <el-col :span="24">企业宣传图:</el-col>
                        <el-col :span="24">
                            <template v-if="companyInfoData.publicizePhoto">
                                <el-row gutter="10">
                                    <el-col :span="2" v-for="(photo,index) in JSON.parse(companyInfoData.publicizePhoto)" :key="index">
                                        <el-image style="width: 100%;max-height: 150px;" :src="photo.url" fit="fill" />
                                    </el-col>
                                </el-row>
                            </template>
                            <template v-else>暂无图片</template>
                        </el-col>
                    </el-row>
                </el-col>
                 <el-col :span="24" class="marginTop10">
                    <el-row>
                        <el-col :span="24">发货印章:</el-col>
                        <el-col :span="24">
                            <template v-if="companyInfoData.shippingSignet">
                                <el-row gutter="10">
                                    <el-col :span="2" v-for="(photo,index) in JSON.parse(companyInfoData.shippingSignet)" :key="index">
                                        <el-image style="width: 100%;max-height: 150px;" :src="photo.url" fit="fill" />
                                    </el-col>
                                </el-row>
                            </template>
                            <template v-else>暂无图片</template>
                        </el-col>
                    </el-row>
                </el-col>
                <el-col :span="24" class="marginTop10">
                    <el-row>
                        <el-col :span="24">产品服务图:</el-col>
                        <el-col :span="24">
                            <template v-if="companyInfoData.productPhoto">
                                <template v-for="(item,index) in JSON.parse(companyInfoData.productPhoto)" :key="index">
                                    <p>{{item.title}}</p>
                                    <el-row gutter="10">
                                        <el-col :span="2" v-for="(photo,index) in item.photo" :key="index">
                                            <el-image style="width: 100%;max-height: 200px;" :src="photo.url" fit="fill" />
                                        </el-col>
                                    </el-row>
                                </template>
                            </template>
                        </el-col>
                    </el-row>
                </el-col>              
                <el-col :span="24" class="marginTop10">
                    <el-row>
                        <el-col :span="24">企业介绍:</el-col>
                        <el-col :span="24">{{companyInfoData.publicizeIntroduce || '--'}}</el-col>
                    </el-row>
                </el-col>
            </el-row>
       </el-card>
       <el-card class="marginTop10">
            <span class="_before">银行账户</span>
            <el-row justify="start">
                <el-col :span="10" class="text-center marginTop10">银行名称：{{companyInfoData.bank || '--'}}</el-col>
                <el-col :span="10" class="text-center marginTop10">RMB账户：{{companyInfoData.rmbAccount || '--'}}</el-col>
                <el-col :span="10" class="text-center marginTop10">SWIFT CODE：{{companyInfoData.swiftCode || '--'}}</el-col>
                <el-col :span="10" class="text-center marginTop10">USD账户：{{companyInfoData.usdAccount || '--'}}</el-col>
            </el-row>
       </el-card>
       <el-card class="marginTop10">
            <span class="_before">企业认证</span>
            <el-row class="marginTop20">
                <el-col :span="8">
                    <el-row class="topContent">
                        <el-col :span="24">营业执照：</el-col>
                        <template v-if="companyInfoData.businessLicense">
                            <el-col :span="12" v-for="(item,index) in JSON.parse(companyInfoData.businessLicense)" :key="index">
                                <el-image style="width: 50%;" :src="item.url" fit="fill" />
                            </el-col>
                        </template>
                    </el-row>
                </el-col>
                <el-col :span="12">
                    <el-row gutter="10">
                        <el-col :span="24">法人身份证：</el-col>
                        <template v-if="companyInfoData.identityPhoto">
                            <el-col :span="4" v-for="(item,index) in JSON.parse(companyInfoData.identityPhoto)" :key="index">
                                <el-image style="width: 100%;max-height: 200px;" :src="item.url" fit="fill" />
                            </el-col>
                        </template>
                    </el-row>
                </el-col>
            </el-row>
       </el-card>
       <el-card class="marginTop10">
            <span class="_before">联系方式</span>
            <el-row>
                <el-col :offset="1" :span="8" class="marginTop10">联系人：{{companyInfoData.contacts || '--'}}</el-col>
                <el-col :span="12" class="marginTop10">所在地：{{companyInfoData.location || '--'}}</el-col>
                <el-col :offset="1" :span="8" class="marginTop10">联系电话：{{companyInfoData.tel || '--'}}</el-col>
                <el-col :span="12" class="marginTop10">详细地址：{{companyInfoData.detailedAddress || '--'}}</el-col>
                <el-col :offset="1" :span="23" class="marginTop10">邮箱地址：{{companyInfoData.email || '--'}}</el-col>
            </el-row>
       </el-card>
       <el-card class="marginTop20">
            <el-row justify="center" class="marginTop10">
                <el-col :span="3"> <el-button type="danger" plain @click="setReject(companyInfoData)">驳回</el-button></el-col>
                <el-col :span="3"><el-button type="success" @click="toExamine(companyInfoData)">通过</el-button></el-col>
            </el-row>
       </el-card>
    </div>
</template>

<script lang="ts" setup>
import { reactive, onMounted, ref } from 'vue'
import { formatDate,warTime } from '@/utils'
import { companyInfo,updateSysCompanyExamineStatus} from '@/api/enterpriseManage/index'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRoute } from 'vue-router'
const route = useRoute()

const companyInfoData = ref({})
const getCompanyInfo = async() =>{
    if(!route.query.id) return
    await companyInfo(route.query.id).then(res => {
        console.log(res)
        if(res.code == '00000'){
            companyInfoData.value = res.data
        }else{
            companyInfoData.value = {}
        }
    })
}
onMounted(() => {
    getCompanyInfo()
})


const chekMainBusiness = (val) =>{
    if(!val) return ''
    try { 
        val = JSON.parse(val)
    } catch (error) {
        val = val
    }
    let str = ''
    let valLength = val.length
    val.forEach((item,index) => {
        if(index == (valLength -1)){
            str = str + item.name
        }else{
            str = str + item.name + '/'
        }
        
    })
    return str  
}


// 审核
const toExamine = (row) =>{
    console.log("row",row)
    if(row.id == '1' || row.id == '6') return ElMessage.warning('内部账号，禁止该操作')
    const data = { id: row.id, examineStatus: 10, rejectReason: '' }
    updateSysCompanyExamineStatus(JSON.stringify(data)).then(res => {
        ElMessage({
            type: 'success',
            message: '通过操作成功',
        })
    })
}
//驳回
const setReject = (row) => {
    if(row.id == '1' || row.id == '6') return ElMessage.warning('内部账号，禁止该操作')
    ElMessageBox.prompt('请输入驳回原因', '您确定要驳回该条申请吗？', {
        confirmButtonText: '确定',
        cancelButtonText: '关闭',
        inputPattern: /\S/,
        inputErrorMessage: '驳回原因',
    }).then(({ value }) => {
        const data = { id: row.id, examineStatus: 15, rejectReason: value }
        updateSysCompanyExamineStatus(JSON.stringify(data)).then(res => {
            ElMessage({
                type: 'success',
                message: '驳回申请成功',
            })
        }).cache(() => {
            ElMessage({
                type: 'info',
                message: '驳回申请失败1',
            })
        })
    }).catch(() => {
        // ElMessage({
        //     type: 'info',
        //     message: '终止驳回操作',
        // })
    })
}
</script>

<style lang="scss" scoped>
.enterpriseDetails{
    padding: 0 20px;
}
.topContent{
    margin-left: 20px;
}
</style>
